package com.meida.boot.handler;

import com.meida.common.enums.AccountTypeEnum;
import com.meida.common.mybatis.entity.EntityMap;
import com.meida.common.mybatis.interceptor.PageInterceptor;
import com.meida.common.mybatis.model.PageParams;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.common.security.OpenHelper;
import com.meida.module.user.client.entity.AppAccount;
import com.meida.module.user.client.entity.AppDept;
import com.meida.module.user.client.entity.AppPosition;
import com.meida.module.user.client.entity.AppUser;
import org.springframework.stereotype.Component;

/**
 * 企业用户列表
 * @author Administrator
 */
@Component("userListHandler")
public class UserListHandler implements PageInterceptor {

    @Override
    public void prepare(CriteriaQuery cq, PageParams pageParams, EntityMap params) {
        Long companyId = OpenHelper.getCompanyId();
        cq.select(AppAccount.class, "account");
        cq.select(AppDept.class, "deptName");
        cq.select(AppPosition.class, "positionName");
        cq.eq(AppUser.class, "companyId", companyId);
        cq.eq(AppAccount.class, "accountType", AccountTypeEnum.USERNAME);
        cq.createJoin(AppAccount.class).right();
        cq.createJoin(AppDept.class);
        cq.createJoin(AppPosition.class);
    }
}
